This assignment consists in creating a staked bar chart with plotly of tornadoes that were log for Texas since 1950. The data was downloaded from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database (https://www.ncei.noaa.gov/pub/data/swdi/stormevents/csvfiles/). The data contains a lot of information (52 columns), types of weather events, fatalities…for each state spaning from 1950-2021. A subset of the data is used in this assignmnet, only data for Texas will used focusing on year atronado events and their associated F-scale (The Fujita Scale of Tornado Intensity, F0 -F5 with incresing estimated wind speeds). No data for 2014 was obtained, issue with downloaded source file, additionaly, some tornadoes events did not have an associated F scale but they were included as “F?”.
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(plotly)
storm_data_s_TX <- read.csv(paste0(getwd(), "/storm_data_s_TX.csv"))
# cumulative sum per F-scale and Year
T3 <- storm_data_s_TX %>%
select(Code,STATE, YEAR, F_scale, timestamp) %>%
group_by(YEAR, F_scale) %>%
arrange(YEAR) %>%
summarize(n=n()) %>%
mutate(cumul_twisters_y = cumsum(n)) %>%
ungroup
bchart<- plot_ly(T3, x = ~YEAR, y = ~cumul_twisters_y, type = 'bar', color= ~F_scale)
bchart <- bchart %>% layout(title = "Tornadoes in Texas 1950-2021",
yaxis = list(title = 'Tornadoe count'), barmode = 'stack',
autosize = F, width = 900, height = 500)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
bchart